package com.ztman.router.common.utils;

import android.content.Context;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
/**
 * @Title:KeyBoardUtil
 * @Package:com.ztman.router.common.utils
 * @Description:控制键盘的显示和隐藏工具类
 * @Auther:YJH
 * @Email:yuannunhua@gmail.com
 * @Date:2018/5/917:17
 */
public class KeyBoardUtils {

    /**
     * 功能：显示
     * @param context
     * @param editText
     */
    public static void openKeyboard(Context context, EditText editText) {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        assert imm != null;
        imm.showSoftInput(editText, InputMethodManager.RESULT_SHOWN);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
    }

    /**
     * 功能：隐藏
     * @param context
     * @param editText
     */
    public static void closeKeyboard(Context context, EditText editText) {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        assert imm != null;
        imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
    }
}
